<?php


namespace app\admin\model;


use app\common\model\BaseModel;

class HouseErr extends BaseModel {

    /**
     * 纠错列表
     * @param $params
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getList($params) {
        $map = [];
        $map[] = ['he.house_id', '=', $params['id']];
        if (isset($params['status']) && $params['status'] == 0) {
            $map[] = ['he.status', '=', 0];
        } elseif (isset($params['status']) && $params['status'] == 1) {
            $map[] = ['he.status', '=', 1];
        }
        $data = db('house_err')
            ->alias('he')
            ->leftjoin('company c', 'c.id = he.company_id')
            ->where($map)
            ->field('c.logo,c.name,he.content,he.status,he.id,he.house_id')
            ->order('id desc')
            ->select();
        foreach ($data as $k => $v) {
            $data[$k]['logo'] = $data[$k]['logo'] ?? '';
            $data[$k]['name'] = $data[$k]['name'] ?? '';
        }
        $count = count($data);
        return [$count, $data];
    }

    /**
     * 操作成功
     * @param $params
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public static function deal($params) {
        db('house_err')->where('id', 'in', $params['id'])->update(['status' => 1]);
    }

}